home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / hyper / hsc_source.lha / hsc / source / ugly / uargs.h < prev    next >
C/C++ Source or Header  |  1996-11-15  |  6KB  |  183 lines

  1. /*
  2.  * ugly/uargs.h
  3.  *
  4.  * ugly argument handling functions, header file
  5.  *
  6.  */
  7.  
  8. #ifndef UGLY_UARGS_H
  9. #define UGLY_UARGS_H
  10.  
  11. /*
  12.  * includes
  13.  */
  14. #include <stdio.h>
  15. #include <stdarg.h>
  16.  
  17. #include "utypes.h"
  18. #include "umemory.h"
  19.  
  20. /*
  21.  * argument errors (returned by _set_args())
  22.  */
  23. #define ASE_NO_MEM                0x01  /* out of memory */
  24. #define ASE_INVALID_NUM           0x02  /* invalid number format */
  25. #define ASE_REQUIRED_MISS         0x03  /* required argument missing */
  26. #define ASE_OUT_OF_RANGE          0x04  /* out of range (LONG, ULONG) */
  27. #define ASE_INVALID_ENUM          0x05  /* invalid enum identifier (ENUM) */
  28. #define ASE_EMPTY_TEMPLATE        0x06  /* empty template (arglist==NULL) */
  29. #define ASE_UNKNOWN_KEYWORD       0x07  /* unknown keyword */
  30. #define ASE_OCCURED_TWICE         0x08  /* arg w/o /O or /M occured twice */
  31. #define ASE_NO_VAL_AFTER_KW       0x09  /* value after keyword missing */
  32.  
  33. #define ASE_HANDLE_FUNC           0x7f  /* error reported by handle func */
  34.  
  35. /*
  36.  * argument errors (returned by _prep_args())
  37.  */
  38. #define APE_NO_MEM                0x01  /* out of memory */
  39. #define APE_INVALID_TEMPLATE      0x02  /* invalid template */
  40. #define APE_DOUBLE_TEMPLATE       0x03  /* doubel definition of template */
  41. #define APE_EMPTY_TEMPLATE        0x04  /* empty template */
  42. #define APE_ILLEGAL_TYPE          0x05  /* unknown type */
  43. #define APE_ILLEGAL_FLAG          0x06  /* unknown flag */
  44. #define APE_DESTVAR_IS_NULL       0x07  /* destination var is NULL */
  45. #define APE_DOUBLE_MULTIPLE       0x08  /* /M used twice */
  46. #define APE_CONFLICTING_M_O       0x09  /* /M and /O both occured */
  47.  
  48. /*
  49.  * argument types
  50.  */
  51. #define ARG_SWITCH     0x01     /* S */
  52. #define ARG_TEXT       0x02     /* T */
  53. #define ARG_LONG       0x03     /* L */
  54. #define ARG_LONG_RANGE 0x04     /* R */
  55. #define ARG_ENUM       0x05     /* E */
  56. #define ARG_ULONG      0x06     /* U */
  57.  
  58. /*
  59.  * argument flags
  60.  */
  61. #define ARG_KEYWORD         ( 1 << 0 )  /* K */
  62. #define ARG_REQUIRED        ( 1 << 1 )  /* R */
  63. #define ARG_MULTIPLE        ( 1 << 2 )  /* M */
  64. #define ARG_CASESENS        ( 1 << 3 )  /* C - case sensitive */
  65. #define ARG_OVERWRITE       ( 1 << 4 )  /* O - overwrite old value when */
  66.                                        /*     occurend more then once */
  67. #define ARG_HANDLEFUNC      ( 1 << 5 )  /* $ */
  68.  
  69. /* values for arginfo.ai_set */
  70. #define AIS_UNSET        0 /* not set at all */
  71. #define AIS_SET_PREVIOUS 1 /* set by previous set_args() */
  72. #define AIS_SET_LOCAL    2 /* set by current set_args() */
  73.  
  74. /*
  75.  * struct arginfo (PRIVATE,DON NOT USE)
  76.  */
  77. typedef struct arginfo
  78. {
  79.     STRPTR ai_id;               /* arg id string */
  80.     LONG ai_type;               /* arg type */
  81.     LONG ai_flags;              /* arg flags */
  82.     union
  83.     {
  84.         STRPTR ai_enum;         /*   enumerator string */
  85.         LONG ai_lolim;          /*   lower limit for range */
  86.     }
  87.     ai_misc1;                   /* type depending information */
  88.     union
  89.     {
  90.         LONG ai_uplim;          /*   upper limit for range */
  91.     }
  92.     ai_misc2;                   /* type depending information */
  93.     APTR ai_dest;               /* ptr to destination var */
  94.       STRPTR(*ai_func) (STRPTR);        /* additional arg handling function */
  95.     STRPTR ai_help;             /* help text */
  96.     BOOL ai_set;                /* handled by _set_args() */
  97. } ARGINFO;
  98.  
  99. typedef struct argfile
  100. {
  101.     int argc;
  102.     char **argv;
  103. } ARGFILE;
  104.  
  105. /*
  106.  * commments about ARGINFO
  107.  *
  108.  * handle function:
  109.  *   the handle function is called by set_arg_value() AFTER the
  110.  *   destination var is updated. the old value is passed as an
  111.  *   APTR to the handle. the handle should return a ptr to a
  112.  *   string that contains an error message or NULL if the new
  113.  *   arg is ok.
  114.  *
  115.  *   example for a handle function for numeric args
  116.  *   STRPTR handle_func( STRPTR newval )
  117.  *   {
  118.  *       STRPTR errmsg = NULL;
  119.  *
  120.  *       printf( "handle_func: set val to %d", newval );
  121.  *       if ( newval > 3 )
  122.  *          errmsg = "val to high!\n";
  123.  *       else if ( newval < 1 )
  124.  *          errmsg = "val to low!\n";
  125.  *
  126.  *       return ( errmsg );
  127.  *   }
  128.  */
  129.  
  130. /*
  131.  * struct arglist (PRIVATE)
  132.  */
  133. typedef struct arglist
  134. {
  135.     STRPTR al_name;             /* name (only for debugging) */
  136.     struct dllist *al_list;     /* argument template */
  137.     struct arginfo *al_multiple;        /* entry with /M flag set */
  138.     struct arginfo *al_nokeywd; /* entry w/o /K flag; TODO: remove */
  139. } ARGLIST;
  140.  
  141. /* debuggin define */
  142. #if DEBUG_UGLY_ARG
  143. #define DA(x) x
  144. #define DUA "*args  * "
  145. #else
  146. #define DA(x)                   /* nufin */
  147. #define DUA                     /* nufin */
  148. #endif
  149.  
  150. /*
  151.  * extern functions & global vars
  152.  */
  153.  
  154. #ifndef NOEXTERN_UGLY_UARGS_H
  155.  
  156. extern LONG prep_error_num;
  157. extern int prep_error_idx;
  158. extern size_t prep_error_pos;
  159.  
  160. extern ARGLIST *prepare_args(STRPTR arglist_name,...);
  161. extern BOOL set_args(int argc, char *argv[], ARGLIST *al);
  162. extern BOOL set_args_argv(int argc, char *argv[], ARGLIST * al);
  163. extern BOOL set_args_file(ARGFILE *argf, ARGLIST *argl);
  164. extern VOID free_args(ARGLIST *al);
  165. extern BOOL check_args(ARGLIST *al);
  166.  
  167. extern ARGFILE *new_argfile(char *argfname);
  168. extern ARGFILE *new_argfilev(STRPTR fname[]);
  169. extern VOID del_argfile(ARGFILE *argf);
  170.  
  171. /* display help */
  172. extern int fprintf_arghelp(FILE * stream, ARGLIST *al);
  173. extern int fprintf_arghelp_short(FILE * stream, ARGLIST *al);
  174.  
  175. /* error handling */
  176. extern STRPTR strargerr(VOID);
  177. extern void pargerr(VOID);
  178.  
  179. #endif /* NOEXTERN_UGLY_UARGS_H */
  180.  
  181. #endif /* UGLY_UARGS_H */
  182.  
  183.